import { Tool } from '../../../Tool';

/**
 * 构件着色
 */
export class ComponentColorTool extends Tool {
	constructor(viewer, color) {
		super(arguments);
		this.viewer = viewer;
		this.color = color || 'rgba(6,206,174,1)';
		this.layers = [];
		this.handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
	}

	start() {
		this.handler.setInputAction((e) => {
			const pick = this.viewer.scene.pick(e.position);
			if (!pick) return;
			const layer = pick?.primitive;

			this.layers.push(layer);
			layer?.setObjsColor(pick.id, Cesium.Color.fromCssColorString(this.color));
		}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
	}

	cancel() {
		this.handler?.destroy();
		for (const layer of this.layers) {
			layer.removeAllObjsColor();
		}
	}
}
ComponentColorTool.toolId = 'ComponentColorTool';
